data(rest_inspec) 
rest_df = rest_inspec %>% 
  select(boro, cuisine_description, score, dba, inspection_date, grade, zipcode) %>% 
  drop_na(score) %>% 
  drop_na(grade) %>%
  filter(boro != "Missing") %>% 
  mutate(cuisine_description = ifelse(as.character(cuisine_description) == "Latin (Cuban, Dominican, Puerto Rican, South & Central American)", "Latin", as.character(cuisine_description)))
rest_df %>% 
  filter(boro == "QUEENS") %>%
  count(cuisine_description) %>%
  top_n(5, n) %>% 
  mutate(cuisine_description = fct_reorder(cuisine_description, n)) %>% 
  plot_ly(x = ~cuisine_description, y = ~n, color = ~cuisine_description, type = "bar", colors = "viridis") %>%
  layout(
    title = "5 Most Common Cuisine Types in Queens",
    xaxis = list(title = "Cuisine Types"),
    yaxis = list(title = "Number of Restaraunts")
  )
rest_df %>% 
  mutate(boro = fct_reorder(boro, score)) %>% 
  plot_ly(y = ~score, color = ~boro, type = "box", colors = "viridis") %>% 
    layout(
    title = "Restaurant Inspection Score by New York Borough",
    xaxis = list(title = "Borough"),
    yaxis = list(title = "Restuarant Inspection Scores")
  )
plot3_df = rest_df %>%
  select(boro, dba, score, inspection_date, grade) %>% 
  group_by(boro, inspection_date, grade, dba) %>% 
  summarize(
    score_avg = mean(score))
## `summarise()` has grouped output by 'boro', 'inspection_date', 'grade'. You can
## override using the `.groups` argument.
plot3_df %>%
  filter(grade == "A" | grade == "B" | grade == "C") %>%
  mutate(text_label = str_c("Restaraunt: ", dba, "\nGrade: ", grade)) %>% 
  plot_ly(
    x = ~inspection_date, y = ~score_avg, type = "scatter", mode = "lines", linetype = ~boro, colors = "viridis", text = ~text_label, alpha = 0.5) %>% 
  layout(
    title = "Trends in NYC Restaraunt Scores Over Time",
    xaxis = list(title = "Date"),
    yaxis = list(title = "Restaraunt Score")
  )